package com.collect.cameroon.zhiScene.zhiRemind.zhiWhatsappService;

import android.content.Context;

import com.collect.cameroon.zhiBase.BasePresenter;
import com.collect.cameroon.zhiBase.BaseSubscriber;
import com.collect.cameroon.zhiBean.zhiReceive.ZHIRCustomerWhatsAppAccountFollow;
import com.collect.cameroon.zhiBean.zhiSend.ZHISCustomerWhatsAppAccountFollow;
import com.collect.cameroon.zhiBean.zhiSend.ZHISSendSmsEntity;
import com.collect.cameroon.zhiNetApi.ZHIHttpApiProvider;
import com.collect.cameroon.zhiNetApi.ZHIHttpResponse;
import com.collect.cameroon.zhiUtils.RxSchedulers;

import java.util.ArrayList;

import javax.inject.Inject;

public class CTWhatsappServicePresenter  extends BasePresenter<CTWhatsappServiceContract.View> implements CTWhatsappServiceContract.Presenter {

    @Inject
    public CTWhatsappServicePresenter() {

    }

    @Override
    public void customerWhatsAppAccountList(Context context, final ZHISSendSmsEntity zhisSendSmsEntity, boolean showLoading) {
        BaseSubscriber<ZHIHttpResponse<ArrayList<ZHIRCustomerWhatsAppAccountFollow>>> subscriber = new
                BaseSubscriber<ZHIHttpResponse<ArrayList<ZHIRCustomerWhatsAppAccountFollow>>>(context, this, showLoading) {
                    @Override
                    protected void onSuccess(Object object) {
                        try {
                            ArrayList<ZHIRCustomerWhatsAppAccountFollow> zhirCustomerWhatsAppAccountFollow = (ArrayList<ZHIRCustomerWhatsAppAccountFollow>) object;
                            mView.onCustomerWhatsAppAccountList(zhirCustomerWhatsAppAccountFollow);
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    }

                    @Override
                    protected void onFailure(int code, String messge) {
                        showMessage(messge);
                        mView.onGetErrorInfo();
                    }
                };
        ZHIHttpApiProvider.getApi().customerWhatsAppAccountList(zhisSendSmsEntity)
                .compose(RxSchedulers.applySchedulers())
                .compose(mView.bindToLife())
                .subscribe(subscriber);
    }

    @Override
    public void customerWhatsAppAccountFollow(Context context, ZHISCustomerWhatsAppAccountFollow zhiSCustomerWhatsAppAccountFollow, boolean showLoading) {
        BaseSubscriber<ZHIHttpResponse> subscriber = new
                BaseSubscriber<ZHIHttpResponse>(context, this, showLoading) {
                    @Override
                    protected void onSuccess(Object object) {
                        try {
                            mView.onCustomerWhatsAppAccountFollow();
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    }

                    @Override
                    protected void onFailure(int code, String messge) {
                        showMessage(messge);
                        mView.onGetErrorInfo();
                    }
                };
        ZHIHttpApiProvider.getApi().customerWhatsAppAccountFollow(zhiSCustomerWhatsAppAccountFollow)
                .compose(RxSchedulers.applySchedulers())
                .compose(mView.bindToLife())
                .subscribe(subscriber);
    }
}
